package consumidor;

/*
 * Copyright 2011 Oracle and/or its affiliates.
 * All rights reserved.  You may not modify, use,
 * reproduce, or distribute this software except in
 * compliance with  the terms of the License at:
 * http://developers.sun.com/license/berkeley_license.html
 */


import com.sun.jmx.snmp.Enumerated;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.jms.MessageListener;
import javax.jms.Message;
import javax.jms.TextMessage;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.naming.NamingEnumeration;
import facades.business.PagoTarjeta;
import facades.business.PagoFailpal;


/**
 * The TextListener class implements the MessageListener
 * interface by defining an onMessage method that displays
 * the contents of a TextMessage.
 *
 * This class acts as the listener for the SimpleAsynchConsumer
 * class.
 */
public class TextListener implements MessageListener {
    /**
     * Casts the message to a TextMessage and displays its text.
     *
     * @param message     the incoming message
     */
    public void onMessage(Message message) {
        MapMessage msg = null;
       ArrayList a=new ArrayList();
       
        try {
            if (message instanceof MapMessage)
            {
                msg =  (MapMessage) message;
                String tipoPago=msg.getString("tipoPago");
                if(tipoPago.equalsIgnoreCase("Tarjeta"))
                {
                    PagoTarjeta pt = new PagoTarjeta();
                    pt.mostrarMensaje(msg);
                   
                }
                else if(tipoPago.equalsIgnoreCase("FailPal"))
                {
                    PagoFailpal pf=new PagoFailpal();
                    pf.mostrarMensaje();
                }
                else
                {
                     System.err.println("El mensaje recibido no es valido");
                }
            } 
            else
            {
                System.err.println("Message is not a MapMessage");
            }
        } catch (JMSException e) {
            System.err.println("JMSException in onMessage(): " + e.toString());
        } catch (Throwable t) {
            System.err.println("Exception in onMessage():" + t.getMessage());
        }
    }
}
